<template>
  <Modal v-model="modal.show" width="350" title="审核">
    <Form ref="formRef" :model="formItem" :rules="ruleValidate" :label-width="70">
      <FormItem label="状态" prop="status">
        <RadioGroup v-model="formItem.status">
          <Radio label="1">
            <span>通过</span>
          </Radio>
          <Radio label="-1">
            <span>驳回</span>
          </Radio>
        </RadioGroup>
        <!-- <Switch v-model="formItem.status" @on-change="change" /> -->
      </FormItem>
      <FormItem v-if="formItem.status == -1" label="原因" prop="memo"
        ><Input v-model="formItem.memo" placeholder="" style="width: 200px" />
      </FormItem>
    </Form>
    <template #footer>
      <div>
        <Button type="text" @click="closeModal">取消</Button>
        <Button type="primary" @click="handleOk">确定</Button>
      </div>
    </template>
  </Modal>
</template>
<script setup>
import http from '@/util/http'
let { proxy } = getCurrentInstance()
const emit = defineEmits(['initList'])
let modal = reactive({ show: false, title: '' })
const formRef = ref(null)

let formItem = reactive({
  recordID: '',
  listID: '',
  status: '1',
  memo: '',
})

const ruleValidate = {
  status: [{ required: true, message: '请选择', trigger: 'blur' }],
}
const closeModal = () => {
  modal.show = false
}

const show = (data) => {
  formRef.value.resetFields()
  modal.show = true
  formItem.listID = data.listID
}

const handleOk = () => {
  formRef.value.validate((valid) => {
    if (valid) {
      http.post('/Settlement/List/Check', toRaw(formItem), (response) => {
        if (response.data.flag) {
          emit('initList')
          proxy.$Message.success(response.data.msg)
          modal.show = false
        } else {
          proxy.$Message.error(response.data.msg)
        }
      })
    } else {
      return false
    }
  })
}

defineExpose({
  show,
})
</script>
